$(function () {
    let markId = getUrlString('markid');
    let userid;
    //获取用户信息
    function getsetting () {
        getData('get','/niu/apiv3/member_getsetting.php',{'markid':markId},function (data) {
            console.log(data);
            userid = data.userid;
            getGroupList();
        })
    }

    getsetting();


    //获取群组列表
    function getGroupList() {
        getData('get','/niu/apiv3/member_jmessage_group.php?method=getAppGroups',null,function (data) {
            console.log(data);
            let append = '';
            $(data.body.groups).each(function () {
                append += '<li>' +
                    '       <input class="name" type="hidden" value="' + this.gid + '">' +
                    '            <div class="left">' +
                    '                <img src="../../res/img/messages/headPic.png" alt="">' +
                    '            </div>' +
                    '            <div class="right">' + this.name + '</div>' +
                    '        </li>'
            });
            $('#conversationList').append(append);
            //群聊消息
            $('#conversationList li').click(function () {
                let groupid = $(this).find('input').val();
                layer.confirm('请确认是否加入该群组？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    var parameter = {
                        'groupid':groupid,
                        'userid':'djuser_'+userid
                    };

                    getData('post','/niu/apiv3/member_jmessage_group.php?method=addGroupMember',parameter,function (data) {
                        console.log(data);
                        if (data.body === null){
                            laymsg('加入成功')
                        } else {
                            laymsg(data.body.error.message)
                        }
                    })
                }, function(){

                });
            });
        })
    }
});